<template>
  <x-main>
    <x-table ref="table" :isPage="true" @search="onSearch" @modify="onModify" showCheckbox>
      <template v-slot:btn-tool>
        <el-button type="primary" @click="onAdd">新增</el-button>
      </template>
      <template #demo="scope">
        <div @click="onDictData" style="cursor: pointer">点击跳转</div>
      </template>
    </x-table>
  </x-main>
</template>

<script setup name="sys-dict-index">
import useStore from '@/stores/modules/sys/dict';
const sysDict = useStore();

import XForm from "./Form.vue"

import {onMounted, ref} from "vue";
import {useRouter} from "vue-router";
const router = useRouter()

onMounted(() => {
  sysDict.init(table)
  sysDict.getList(1, 10);
})

let table = ref();

/**
 * 搜索
 * @param pageNo
 * @param pageSize
 * @param condition
 */
const onSearch = (pageNo, pageSize, condition) => {
  sysDict.getList(pageNo, pageSize, condition);
}

/**
 * 新增
 * @returns {Promise<void>}
 */
const onAdd = async () => {
  const op = Dialog.open(XForm, "添加字典类型")
  op.setWidth(600)

  op.confirm(c=> {
    c.submit()
  })
}

const onModify = () => {
  const op = Dialog.open(XForm, "修改字典类型")
  op.setWidth(600)

  op.confirm(c=> {
    c.submit()
  })
}

const onDictData = () => {
  router.push("/sys/dict-data")
}
</script>
